/**
 * 询价.COM v1.0.0
 * http://xun-jia.com/
 *
 * Copyright (c) 2009 
 * 四川漾天空网络科技有限公司
 * 成都市天府软件园A3栋2楼
 *
 */
package com.xunjia.util;

import java.io.Serializable;
import java.util.Map;

/**
 * @author Mark
 * 
 * @Email Mark_yang@xun-jia.com
 * 
 * @Date 2009-4-22 上午10:39:01
 * 
 */
public class HttpSessionUtils implements Serializable {

	private static final long serialVersionUID = 5415725890732252300L;

	/**
	 * 将目标对象保存至SESSION
	 * 
	 * @param session
	 * @param key
	 * @param obj
	 */
	@SuppressWarnings("unchecked")
	public static void copyObjectToSession(Map<String, Object> session, String key, Object obj, Class objClass) {
		Object dest = null;
		if (obj instanceof String) {
			dest = obj;
		} else {
			dest = PropertyUtil.copyProperties(obj, objClass);
		}
		session.put(key, dest);
	}

	/**
	 * 从SESSION中获取指定键的对象
	 * 
	 * @param session
	 * @param key
	 * @return
	 */
	public static Object getObjectFromSession(Map<String, Object> session, String key) {
		return session.get(key);
	}

	/**
	 * 从SESSION中删除指定键的对象
	 * 
	 * @param session
	 * @param key
	 * @return
	 */
	public static void deleteObjectFromSession(Map<String, Object> session, String key) {
		session.remove(key);
	}

	/**
	 * 清空SESSION
	 * 
	 * @param session
	 * @param key
	 * @return
	 */
	public static void clearSession(Map<String, Object> session) {
		session.clear();
	}
}
